﻿/* Author:
 * Alessandro Pulidori
 * Andrea Russino
 *  Andrea Vandin
 */
using System;
using System.Linq;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using CompactFramework.Utilities.Localization;

using TripLOAMobile.InternalEntities;
using TripLOAMobile.InternalEntities.ExtensionsMethods;

namespace TripLOAMobile
{
    /// <summary>
    /// This form visualize the details of a travel
    /// </summary>
    public partial class ShowDetails : LocalizedForm
    {
        private const int MAXNUMBERPASSENGERSFORAIRPLANEANDSHIP = 30;

        private AnimationControl animation;
        private Bitmap m_DoubleBuffer; //Used to avoid flickering effects on paint procedure

        private bool lblStagesEnabled = true,lblTravellersEnabled=true;

        #region Local Variables
        private bool isBookable;
        private string status;
        private WS_SoapTrip.FullTripInfo actualTrip;
        private Point panelOffset;
        
        private bool changesAboutFavorites,changesAboutBooking;
        /// <summary>
        /// Gets a value indicating whether [need to reload the list].
        /// </summary>
        /// <value>
        /// 	<c>true</c> if [need to reload the list]; otherwise, <c>false</c>.
        /// </value>
        public bool NeedToReloadTheList
        {
            get
            {
                return changesAboutFavorites||changesAboutBooking;
            }
        }

        /// <summary>
        /// Gets or sets the actual trip.
        /// </summary>
        /// <value>The actual trip.</value>
        private WS_SoapTrip.FullTripInfo ActualTrip
        {
            set
            {
                actualTrip = value;

                depAddressShower.setAddress(actualTrip.Departure);
                desAddressShower.setAddress(actualTrip.Arrival);

                fldAuthor.Text = value.Owner.Username;

                fldDeparture.Text = value.Departure.getCity(); 
                fldArrival.Text = value.Arrival.getCity(); 
                fldDepDt.Text = value.DepartureDate.Value.ToString("dd/MM/yyyy  HH:mm");
                fldExpires.Text = value.ReservationExpirationDate != null ? value.ReservationExpirationDate.Value.ToString("dd/MM/yyyy  hh:mm") : "";
                fldExtimatedCost.Text = string.Format("{0:F}",value.EstimatedBudget);
                fldSmokers.Checked = value.AcceptSmoker.Value;                
                if (value.RequireLicensed.HasValue)
                    fldLicensed.Checked = value.RequireLicensed.Value;
                else
                    fldLicensed.Checked = false;

                if ((value.Notes != null) && (value.Notes != ""))
                    fldNote.Text = value.Notes;
                else
                    fldNote.Enabled = false;

                if (value.Stages.Length == 0)
                {
                    lblStages.Enabled = false;
                    lblStages.Visible = false;
                    lblStages.Enabled = false;
                    listStages.Visible = false;
                    listStages.Enabled = false;
                    lblTravellers.Location = lblStages.Location;
                    listTravellers.Location = listStages.Location;
                }
                else foreach (WS_SoapTrip.StageInfo stage in value.Stages)
                    listStages.Items.Add(string.Format("{0}-{1} {2:F} km", stage.Origin.Address.getCity(), stage.Destination.Address.getCity(), stage.Distance));
                if (value.ReservatedUsers.Length == 0)
                {
                    lblTravellersEnabled = false;
                    lblTravellers.Visible = false;
                    lblTravellers.Enabled = false;
                    listTravellers.Visible = false;
                    listTravellers.Enabled = false;
                }
                else foreach (TripLOAMobile.WS_SoapTrip.UserInfo ui in value.ReservatedUsers)
                    listTravellers.Items.Add(ui.Username);
            }
            get
            {
                return actualTrip;
            }
        }
        #endregion;

        #region Initialization
        /// <summary>
        /// Make the real initialization of all the displayed informations
        /// </summary>
        /// <param name="details">Details of the trip</param>
        /// <param name="isBookable">The bookable state of the trip</param>
        private void InitializeInformations(TripLOAMobile.WS_SoapTrip.FullTripInfo details)
        {
            if (details != null)
            {
                this.changesAboutFavorites = false;
                this.changesAboutBooking = false;

                #region vincoli sui posti liberi
                this.panelNumberSeats.Enabled = true;
                this.panelNumberSeats.Minimum = 1;
                if (details.Stages[0].Vehicle.MaxSeatNumber == 0)
                    this.panelNumberSeats.Maximum = MAXNUMBERPASSENGERSFORAIRPLANEANDSHIP;
                else
                {
                    int busyseats = (details.Stages[0].BusySeats == null) ? 0 : details.Stages[0].BusySeats.Value;
                    this.panelNumberSeats.Maximum = details.Stages[0].Vehicle.MaxSeatNumber - busyseats;
                }
                #endregion

                if (!this.isBookable)
                {
                    //this.mainMenu1.MenuItems.Clear();
                    this.menuRight.MenuItems.Clear();
                    this.mainMenu1.MenuItems.Remove(this.menuRight);
                }
                else if ((bool)details.IsBooked)
                {
                    this.setBookButtonMeaning(true);
                    this.setFavoritesButtonMeaning(false);
                }
                else if ((bool)details.IsInFavorites)
                {
                    this.setFavoritesButtonMeaning(true);
                    this.setBookButtonMeaning(false);
                }
                else
                {
                    this.setStandardButtonsMeaning();
                }
                ActualTrip = details;
                this.stopAnimation();
            }
            else
            {
                //somehow shows "no details"...
                this.stopAnimation();
                MessageBox.Show(ResourceManager.Instance.GetString("NoDetails"));
                Welcome.formBuffer.Close();
            }
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="ShowDetails"/> class.
        /// </summary>
        /// <param name="id">The id.</param>
        /// <param name="isBookable">if set to <c>true</c> [is bookable].</param>
        public ShowDetails(int id, bool isBookable)
        {
            #region creation of the control for the animation
            animation = new AnimationControl();
            int x = this.Width / 2 - animation.Width / 2;
            int y = this.Height / 2 - animation.Height / 2;
            animation.Location = new Point(x, y);
            this.Controls.Add(animation);
            animation.BringToFront();
            #endregion
            #region DoubleBufferInitialization
            Size cSz = ClientSize;
            m_DoubleBuffer = new Bitmap(cSz.Width, cSz.Height);
            #endregion
            this.isBookable = isBookable;
            Welcome.rrp.GetDetails(this, rrp_DetailsResponse, id);
            InitializeComponent();
            this.AddMenusToDictionary();
            UpdateResources();
            this.panelNumberSeats.Minimum = 1;
            //this.panelNumberSeats.Maximum=mettici il numero di posti disponibili in quello stage
            this.panelBooking.Visible = false;
            this.panelOffset = new Point(this.Width / 2 - this.panelBooking.Width / 2, this.Height / 2 - this.panelBooking.Height / 2);
            //this.panelOffset=new Point(0, 0);
            this.fldNote.ScrollBars = ScrollBars.Vertical;
            fldSmokers.Enabled = false;
            fldLicensed.Enabled = false;
            this.startAnimation();
            if(Welcome.formBuffer.GetFormNames().Contains("SearchTravel"))
                menuItem3.Enabled = true;

            depAddressShower.setLabelsText(ResourceManager.Instance.GetString("street"), ResourceManager.Instance.GetString("city"), ResourceManager.Instance.GetString("province"), ResourceManager.Instance.GetString("zipCode"), ResourceManager.Instance.GetString("nation"));
            desAddressShower.setLabelsText(ResourceManager.Instance.GetString("street"), ResourceManager.Instance.GetString("city"), ResourceManager.Instance.GetString("province"), ResourceManager.Instance.GetString("zipCode"), ResourceManager.Instance.GetString("nation"));

        }

        #region start/stop animation
        delegate void animationDel();
        /// <summary>
        /// Stops the animation.
        /// </summary>
        private void stopAnimation()
        {
            fldAuthor.Enabled = true;
            fldDeparture.Enabled = true;
            fldArrival.Enabled = true;
            fldDepDt.Enabled = true;
            fldExpires.Enabled = true;
            fldExtimatedCost.Enabled = true;
            listStages.Enabled = true;
            lblStages.Enabled = lblStagesEnabled;
            lblTravellers.Enabled = lblTravellersEnabled;

            this.menuLeft.Enabled = true;
            this.menuRight.Enabled = true;
            this.favOp.Enabled = true;
            this.bookOp.Enabled = true;

            if ((fldNote.Text == null) || (fldNote.Text == ""))
                this.fldNote.Enabled = false;

            this.animation.StopAnimation();
            this.AutoScroll = true;
        }
        /// <summary>
        /// Starts the animation.
        /// </summary>
        private void startAnimation()
        {
            fldAuthor.Enabled = false;
            fldDeparture.Enabled = false;
            fldArrival.Enabled = false;
            fldDepDt.Enabled = false;
            fldExpires.Enabled = false;
            fldExtimatedCost.Enabled = false;
            listStages.Enabled = false;
            lblStages.Enabled = false;
            lblTravellers.Enabled = false;


            this.favOp.Enabled = false;
            this.bookOp.Enabled = false;
            this.menuLeft.Enabled = false;
            this.menuRight.Enabled = false;
            this.animation.StartAnimation();
            this.AutoScroll = false;
        }
        #endregion

        /// <summary>
        /// The subclasses of the LocalizedForm should override this method and use this method to
        /// associate all menu items with custom names with the help of <see cref="AddMenuToDictionary"/>
        /// method.
        /// </summary>
        protected override void AddMenusToDictionary()
        {
            this.AddMenuToDictionary(this.bookOp, "bookOp");
            this.AddMenuToDictionary(this.favOp, "favOp");
            this.AddMenuToDictionary(this.menuLeft, "menuLeft");
            this.AddMenuToDictionary(this.menuRight, "menuRight");
            this.AddMenuToDictionary(this.menuItem1, "menuBack");
            this.AddMenuToDictionary(this.menuItem2, "menuHome");
            this.AddMenuToDictionary(this.menuItem3, "menuSearch");
        }
        #endregion;

        #region ResponseHandling
        /// <summary>
        /// Handler of the reception of the remote response
        /// </summary>
        /// <param name="e">The <see cref="TripLOAMobile.RemoteResourceProvider.DetailsResponseEventArgs"/> instance containing the event data.</param>
        void rrp_DetailsResponse(RemoteResourceProvider.DetailsResponseEventArgs e)
        {
            this.status = e.Status;
            stopAnimation();
            if (e.Status == RemoteResourceProvider.okStatus)
            {
                InitializeInformations(e.Details);
            }
            else
            {
                MessageBox.Show(e.Status);
            }
        }

        delegate void LocalHandler (WS_SoapTrip.FullTripInfo details);
        #endregion

        #region methods about booking

        /// <summary>
        /// Books the travel.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void bookTravel(object sender, EventArgs e)
        {
            this.showPanel();
        }

        #region ResponseHandling
        /// <summary>
        /// Handler of the response of a booking request
        /// </summary>
        /// <param name="e">The <see cref="TripLOAMobile.RemoteResourceProvider.BooleanResponseEventArgs"/> instance containing the event data.</param>
        void rrp_BookResponse(RemoteResourceProvider.BooleanResponseEventArgs e)
        {
            this.stopAnimation();
            status = e.Status;
            if (e.Succeed)
            {
                //prenotazione ha avuto successo...
                this.setBookButtonMeaning(true);//disattiva bottone per prenotare/trasformalo in "rimuovi prenotazione..."
                //quando si tornerà nella lista di partenza bisogna ricaricarla...
                this.changesAboutBooking = !this.changesAboutBooking;
            }
            else
            {
                MessageBox.Show(CompactFramework.Utilities.Localization.ResourceManager.Instance.GetString("bookFail") + "- (Status=" + e.Status + ")");
            }
        }
        #endregion

        /// <summary>
        /// Removes the book.
        /// </summary>
        /// <param name="sender">The sender.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void removeBook(object sender, EventArgs e)
        {
            this.startAnimation();
            Welcome.rrp.SendCancelBookingRequest(this, rrp_CancelBookingResponse, actualTrip.ID);
        }

        /// <summary>
        /// Handler of the response of a unbooking request
        /// </summary>
        /// <param name="e">The <see cref="TripLOAMobile.RemoteResourceProvider.BooleanResponseEventArgs"/> instance containing the event data.</param>
        void rrp_CancelBookingResponse(RemoteResourceProvider.BooleanResponseEventArgs e)
        {
            this.stopAnimation();
            status = e.Status;

            if (e.Succeed)
            {
                this.setBookButtonMeaning(false);
                this.changesAboutBooking = !this.changesAboutBooking;
            }
            else
            {
                MessageBox.Show(CompactFramework.Utilities.Localization.ResourceManager.Instance.GetString("unBookFail")+" - ("+e.Status+")");
            }
        }

        /// <summary>
        /// Sets the text and handler of the button about booking
        /// </summary>
        /// <param name="isBooked">if set to <c>true</c> [is booked].</param>
        private void setBookButtonMeaning(bool isBooked)
        {
            if (!this.isBookable)
                return;
            if (isBooked)
            {
                //metti bottone per rimuovere prenotazione
                this.bookOp.Text = ResourceManager.Instance.GetString("ShowDetails_rmBook");
                this.bookOp.Click -= new System.EventHandler(this.bookTravel);
                this.bookOp.Click += new System.EventHandler(this.removeBook);

                //this.addFavoritesMenuItem.Text = "";
                this.favOp.Enabled = false;
            }
            else
            {
                //metti bottone per prenotare
                this.bookOp.Text = ResourceManager.Instance.GetString("ShowDetails_bookOp");
                this.bookOp.Click -= new System.EventHandler(this.removeBook);
                this.bookOp.Click += new System.EventHandler(this.bookTravel);

                this.favOp.Enabled = true;
            }
            Invalidate();
            Update();
        }

        #endregion

        #region methods about favorites

        /// <summary>
        /// Handles the Click event of the addFavoritesMenuItem control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void addFavoritesMenuItem_Click(object sender, EventArgs e)
        {
            this.startAnimation();
            Welcome.rrp.SendAddToFavoritesRequest(this, rrp_AddToFavoritesResponse, actualTrip.ID);
        }

        /// <summary>
        /// Handler of the response of an add to favorite request
        /// </summary>
        /// <param name="e">The <see cref="TripLOAMobile.RemoteResourceProvider.BooleanResponseEventArgs"/> instance containing the event data.</param>
        void rrp_AddToFavoritesResponse(RemoteResourceProvider.BooleanResponseEventArgs e)
        {
            this.stopAnimation();
            status = e.Status;
            if (e.Succeed)
            {
                //prenotazione ha avuto successo...
                this.setFavoritesButtonMeaning(true);
                //quando si tornerà nella lista di partenza bisogna ricaricarla...
                this.changesAboutFavorites = !this.changesAboutFavorites;
            }
            else
            {
                MessageBox.Show(CompactFramework.Utilities.Localization.ResourceManager.Instance.GetString("favFail") + "- (Status=" + e.Status + ")");
            }
        }

        /// <summary>
        /// Handles the Click event of the removeFromFavorites control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void removeFromFavorites_Click(object sender, EventArgs e)
        {
            this.startAnimation();
            Welcome.rrp.SendRemoveFromFavoritesRequest(this, rrp_RemoveFromFavoritesResponse, actualTrip.ID);
        }

        /// <summary>
        /// Handles the response of a rimotion from favorites
        /// </summary>
        /// <param name="e">The <see cref="TripLOAMobile.RemoteResourceProvider.BooleanResponseEventArgs"/> instance containing the event data.</param>
        void rrp_RemoveFromFavoritesResponse(RemoteResourceProvider.BooleanResponseEventArgs e)
        {
            this.stopAnimation();
            status = e.Status;
            if (e.Succeed)
            {
                this.setFavoritesButtonMeaning(false);
                this.changesAboutFavorites = !this.changesAboutFavorites;
            }
            else
            {
                MessageBox.Show(CompactFramework.Utilities.Localization.ResourceManager.Instance.GetString("unFavFail") + "- (Status=" + e.Status + ")");
            }
        }

        /// <summary>
        /// Sets the text and handler of the button about favirutes
        /// </summary>
        /// <param name="isFavorite">if set to <c>true</c> [is favorite].</param>
        private void setFavoritesButtonMeaning(bool isFavorite)
        {
            if (!this.isBookable)
                return;
            if (isFavorite)
            {
                this.favOp.Text = ResourceManager.Instance.GetString("ShowDetails_rmFav");
                this.favOp.Click -= new System.EventHandler(this.addFavoritesMenuItem_Click);
                this.favOp.Click += new System.EventHandler(this.removeFromFavorites_Click);

                this.bookOp.Enabled = false;
            }
            else
            {
                this.favOp.Text = ResourceManager.Instance.GetString("ShowDetails_favOp");
                this.bookOp.Click -= new System.EventHandler(this.removeFromFavorites_Click);
                this.favOp.Click += new System.EventHandler(this.addFavoritesMenuItem_Click);
                this.bookOp.Enabled = true;
            }
            Invalidate();
            Update();
        }
        #endregion

        #region OnPainting
        protected override void OnPaintBackground(PaintEventArgs e)
        {
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);
            using (Graphics g = Graphics.FromImage(m_DoubleBuffer))
            {
                g.Clear(BackColor);
                g.DrawImage(Properties.Resources.circles, 3, AutoScrollPosition.Y + 3);
                Point[] p = new Point[]{
                    new Point(40,AutoScrollPosition.Y + 25), 
                    new Point(195,AutoScrollPosition.Y + 25), 
                    new Point(190,AutoScrollPosition.Y + 30), 
                    new Point(40,AutoScrollPosition.Y + 30)};
                using (Brush b = new SolidBrush(Color.Green))
                    g.FillPolygon(b, p);

                p[0].Y = p[1].Y = AutoScrollPosition.Y + 30;
                p[2].Y = p[3].Y = AutoScrollPosition.Y + 35;
                p[1].X -= 10;
                p[2].X -= 10;
                using (Brush b = new SolidBrush(Color.GreenYellow))
                    g.FillPolygon(b, p);
            }
            using (Graphics g = e.Graphics)
                g.DrawImage(m_DoubleBuffer, 0, 0);
        }

        private void panelBooking_Paint(object sender, PaintEventArgs e)
        {
            using (Graphics g = e.Graphics)
            {
                using (Brush b = new SolidBrush(Color.FromArgb(48, 138, 13)))
                {
                    Rectangle r = new Rectangle(this.panelNumberSeats.Location.X - 3, this.panelNumberSeats.Location.Y - 3, this.panelNumberSeats.Width + 6, this.panelNumberSeats.Height + 6);
                    g.FillRectangle(b, r);
                    r.X = this.panelTolerance.Location.X - 3; r.Y = this.panelTolerance.Location.Y - 3; r.Width = this.panelTolerance.Width + 6; r.Height = this.panelTolerance.Height + 6;
                    g.FillRectangle(b, r);
                    r.X = this.panelNotes.Location.X - 3; r.Y = this.panelNotes.Location.Y - 3; r.Width = this.panelNotes.Width + 6; r.Height = this.panelNotes.Height + 6;
                    g.FillRectangle(b, r);
                }
            }
        }
        #endregion;

        /// <summary>
        /// Sets the text and handlers of the buttons about favirutes and booking
        /// </summary>
        private void setStandardButtonsMeaning()
        {
            if (!this.isBookable)
                return;
            //metti bottone per prenotare
            this.bookOp.Text = ResourceManager.Instance.GetString("ShowDetails_bookOp");
            this.bookOp.Click -= new System.EventHandler(this.removeBook);
            this.bookOp.Click += new System.EventHandler(this.bookTravel);

            //metti bottone per aggiungere ai favoriti
            this.favOp.Text = ResourceManager.Instance.GetString("ShowDetails_favOp");
            this.bookOp.Click -= new System.EventHandler(this.removeFromFavorites_Click);
            this.favOp.Click += new System.EventHandler(this.addFavoritesMenuItem_Click);
        }

        /// <summary>
        /// Handles the Click event of the fldAuth control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void fldAuth_Click(object sender, EventArgs e)
        {
            Welcome.rrp.GetProfile(actualTrip.Owner.UserID, this, rrp_ProfileResponse);
        }

        /// <summary>
        /// Handle the response of a get profile request
        /// </summary>
        /// <param name="e">The <see cref="TripLOAMobile.RemoteResourceProvider.ProfileResponseEventArgs"/> instance containing the event data.</param>
        void rrp_ProfileResponse(RemoteResourceProvider.ProfileResponseEventArgs e)
        {
            if (e.Status == RemoteResourceProvider.okStatus)
            {
                ShowProfileInfo p = new ShowProfileInfo(e.Profile, ActualTrip.Owner.NumericFeedbacks, false);
                Welcome.formBuffer.Add(p, "ShowProfileInfo");
                p.ShowDialog();
                p.Dispose();
            }
            else 
                MessageBox.Show(e.Status);
        }

        /// <summary>
        /// Handles the Click event of the buttonOk control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void buttonOk_Click(object sender, EventArgs e)
        {
            this.hidePanel();
            this.startAnimation();
            //al momento prendo la partenza del primo stage, e la destinazione dell'ultimo...poi prenderemo partenza dallo stage con la partenza che mi interessa, e destinazione da quello con dest che mi interessa...
            ReservationRequest rr = new ReservationRequest(actualTrip.ID, actualTrip.Stages[0].Origin.Coords, actualTrip.Stages[actualTrip.Stages.Length - 1].Destination.Coords,(byte)this.panelNumberSeats.Value,(int)this.panelTolerance.Value,this.panelNotes.Text);
            rr.Departure = actualTrip.Departure;
            rr.Arrival = actualTrip.Arrival;
            Welcome.rrp.SendBookingTravelRequest(this, rrp_BookResponse, rr);
        }

        /// <summary>
        /// Handles the Click event of the buttonBack control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void buttonBack_Click(object sender, EventArgs e)
        {
            this.hidePanel();
        }

        /// <summary>
        /// Hides the panel for booking.
        /// </summary>
        private void hidePanel()
        {
            fldAuthor.Enabled = true;
            fldDeparture.Enabled = true;
            fldArrival.Enabled = true;
            fldDepDt.Enabled = true;
            fldExpires.Enabled = true;
            fldExtimatedCost.Enabled = true;
            listStages.Enabled = true;
            lblStages.Enabled = lblStagesEnabled;
            lblTravellers.Enabled = lblTravellersEnabled;

            this.menuLeft.Enabled = true;
            this.menuRight.Enabled = true;
            this.bookOp.Enabled = true;
            this.favOp.Enabled = true;
            this.AutoScroll = true;
            this.panelBooking.Visible = false;
            this.Invalidate();
            this.Update();
        }
        
        /// <summary>
        /// Shows the panel for booking.
        /// </summary>
        private void showPanel()
        {
            fldAuthor.Enabled = false;
            fldDeparture.Enabled = false;
            fldArrival.Enabled = false;
            fldDepDt.Enabled = false;
            fldExpires.Enabled = false;
            fldExtimatedCost.Enabled = false;
            listStages.Enabled = false;
            lblStages.Enabled = false;
            lblTravellers.Enabled = false;
            
            this.AutoScroll = false;
            this.menuLeft.Enabled = false;
            this.menuRight.Enabled = false;
            this.favOp.Enabled = false;
            this.bookOp.Enabled = false;
            this.panelBooking.Location = new Point(AutoScrollPosition.X + this.panelOffset.X, Math.Abs(AutoScrollPosition.Y) + this.panelOffset.Y);
            this.panelBooking.Enabled = true;
            this.panelBooking.Visible = true;
            this.Invalidate();
            this.Update();
        }

        /// <summary>
        /// Handles the Click event of the menuItem1 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void menuItem1_Click(object sender, EventArgs e)
        {
            Welcome.formBuffer.Close();
        }

        /// <summary>
        /// Handles the Click event of the menuItem2 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void menuItem2_Click(object sender, EventArgs e)
        {
            Welcome.formBuffer.Clear();
        }

        /// <summary>
        /// Handles the Click event of the menuItem3 control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void menuItem3_Click(object sender, EventArgs e)
        {
            Welcome.formBuffer.GoTo("SearchTravel");
        }

        /// <summary>
        /// Handles the Click event of the fldDeparture control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void fldDeparture_Click(object sender, EventArgs e)
        {
            desAddressShower.Hide();
            depAddressShower.Enabled = true;
            depAddressShower.Visible = true;
        }

        /// <summary>
        /// Handles the Click event of the fldArrival control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void fldArrival_Click(object sender, EventArgs e)
        {
            depAddressShower.Hide();
            desAddressShower.Enabled = true;
            desAddressShower.Visible = true;
        }

        /// <summary>
        /// Raises the <see cref="E:System.Windows.Forms.Control.Click"/> event.
        /// </summary>
        /// <param name="e">An <see cref="T:System.EventArgs"/> that contains the event data.</param>
        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);
            this.depAddressShower.Hide();
            this.desAddressShower.Hide();
        }
    }
}